<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <title></title>
    </head>
    <body>
        <button type="button">点击</button>
        <div id="">

        </div>
        <script type="text/javascript">
            var btn = document.querySelector('button');
            var div = document.querySelector('div');
            btn.addEventListener('click', function() {
                location.href = 'http://www.baidu.com';
            })
            var timer = 5;


            setInterval(function() {
                if (timer == 0) {
                    location.href = 'http://www.baidu.com';
                } else {
                    div.innerHTML = '将在' + timer + '秒后自动跳转';
                    timer--;
                }

            }, 1000)

            function fn() {
                if (timer == 0) {
                    location.href = 'http://www.baidu.com';
                } else {
                    div.innerHTML = '将在' + timer + '秒后自动跳转';
                    timer--;
                }
            }
            fn();
        </script>
    </body>
</html>
